package com.LeeCode;

/**
 * 删除链表的中间节点
 */

public class Code2095 {
    public static void main(String[] args) {
        int[] arr = {1, 3};
        ListNode head = Utils.arrayToListNode(arr);
        Utils.printListNode(new Code2095().deleteMiddle(head));
    }

    public ListNode deleteMiddle(ListNode head) {
        if (head.next == null) return null;
        ListNode slow = head, fast = head;
        // 后面还有节点的情况下继续走
        while (fast.next.next != null && fast.next.next.next != null) {
            slow = slow.next;
            fast = fast.next.next;
        }
        slow.next = slow.next.next;
        return head;
    }
}
